#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
@AUTHOR: tyc
@VERSION: 1.0.0
@DESCRIPTION: 搜索超级鹰使用这个来识别验证码 直接下载python demo代码测试即可
# 登录12306
@time: 2021-07-13 14:11:52 
"""
from time import sleep
from selenium.webdriver import Chrome
from chaojiying import Chaojiying_Client

login_url = 'http://www.chaojiying.com/user/login/'
user_name = '18238827823'
pass_word = '147852'
# 超级鹰软件id
software_id = '919585'

browser = Chrome()
browser.get(login_url)

# 获取验证码图片
vertify_img = browser.find_element_by_xpath('/html/body/div[3]/div/div[3]/div[1]/form/div/img').screenshot_as_png
chaojiying = Chaojiying_Client(user_name, pass_word, software_id)
# 获取到验证码
vertify_code = chaojiying.PostPic(vertify_img, 1902)['pic_str']
print(vertify_code)
# 输入用户名密码和验证码
browser.find_element_by_xpath('/html/body/div[3]/div/div[3]/div[1]/form/p[1]/input').send_keys(user_name)
browser.find_element_by_xpath('/html/body/div[3]/div/div[3]/div[1]/form/p[2]/input').send_keys(pass_word)
browser.find_element_by_xpath('/html/body/div[3]/div/div[3]/div[1]/form/p[3]/input').send_keys(vertify_code)
# 点击登录
sleep(2)
browser.find_element_by_xpath('/html/body/div[3]/div/div[3]/div[1]/form/p[4]/input').click()
